package algorithms2.sort;

import java.util.Arrays;

/**
 * @Author: DRevelation
 * @Date: 2021/9/13 10:44
 */
public class InsertSort {

    public static void main(String[] args) {
        int[] nums = {5, 3, 2, 1, 4};
        int[] sortedNums = insertSort(nums);
        System.out.println(Arrays.toString(sortedNums));
    }

    private static int[] insertSort(int[] nums) {
        int len = nums.length;
        for (int i = 0; i < len; i++) {
            for (int j = i; j < len; j++) {
                if (nums[i] > nums[j]) {
                    Utils.swap(nums, i, j);
                }
            }
            System.out.println("第 " + (len - i) + " 次排序结果是: " + Arrays.toString(nums));
        }
        return nums;
    }
}
